package com.sfh.appversion.controller;

import com.sfh.appversion.base.Result;
import com.sfh.appversion.base.page.PageResponse;
import com.sfh.appversion.dao.entity.AppInfoDO;
import com.sfh.appversion.dao.entity.AppVersionAssignDO;
import com.sfh.appversion.dao.entity.AppVersionDO;
import com.sfh.appversion.dto.req.*;
import com.sfh.appversion.dto.resp.AppDowonSizeRespDTO;
import com.sfh.appversion.dto.resp.AppMenuRespDTO;
import com.sfh.appversion.dto.resp.AppVersionCheckRespDTO;
import com.sfh.appversion.server.AppServer;
import com.sfh.appversion.server.AppVersionServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/***
 * 应用
 */
@RestController
@RequestMapping("/app")
public class AppController {

    @Autowired
    private AppServer appService;

    /***
     * 新增应用
     * @param vo
     */
    @PostMapping("add")
    public Result<Boolean> add(@RequestBody  AppNewReqDTO vo) {
        boolean success = appService.add(vo);
        return Result.success(success);
    }

    /***
     * 根据类型获取左侧菜单显示应用集合
     * @param appType
     * @return
     */
    @GetMapping("queryAllList")
    public Result<List<AppMenuRespDTO>> queryAllList(@RequestParam  String appType) {
        return Result.success(appService.queryAllList(appType));
    }

    /***
     * 获取应用信息
     */
    @GetMapping("queryInfo")
    public Result<AppInfoDO> queryInfo(@RequestParam String appId) {
        AppInfoDO appInfoDO = appService.queryInfo(appId);
        return Result.success(appInfoDO);
    }

    /***
     * 编辑应用
     * @param vo
     */
    @PostMapping("edit")
    public Result edit(@RequestBody AppEditReqDTO vo) {
        boolean success = appService.edit(vo);
        return Result.success(success);
    }


    /***
     * 删除应用
     */
    @PostMapping("delete/{appId}")
    public Result<Boolean> delete(@PathVariable String appId) {
        boolean success = appService.del(appId);
        return Result.success(success);
    }

    /***
     * 根据appID  应用位置在菜单第一位
     * @return
     */
    @PostMapping("sortToFrist/{appId}")
    public Result<Boolean> sortToFrist(@PathVariable String appId) {
        return Result.success(appService.sortToFrist(appId));
    }

    /***
     * 根据appID  获取应用下载量
     * @return
     */
    @GetMapping("queryAppDownSize")
    public Result<AppDowonSizeRespDTO> queryAppDownSize(@PathVariable String appId) {
        return Result.success(appService.queryAppDownSize(appId));
    }

    /***
     * 根据appID  获取应用下载地址
     * @return
     */
    @GetMapping("queryAppDownUrl")
    public Result<String> queryAppDownUrl(@PathVariable String appId) {
        return Result.success(appService.queryAppDownUrl(appId));
    }


}
